<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jstl/core_rt" prefix="c" %>
<!DOCTYPE HTML>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <jsp:include page="/resources/inc/head.jsp" />
</head>
<body>
<form class="layui-form layui-form-pane" id="_form">
    <div class="layui-form-item">
        <label class="layui-form-label">品牌名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" lay-verify="required" autocomplete="off" placeholder="请输入品牌名称"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">描述</label>
        <div class="layui-input-block">
            <textarea placeholder="请输入描述" class="layui-textarea" name="description"></textarea>
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="text" name="sort" lay-verify="number" autocomplete="off" placeholder="请输入排序"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">品牌官网</label>
        <div class="layui-input-block">
            <input type="text" name="url" autocomplete="off" placeholder="请输入品牌官网"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-upload" style="display: inline-block;margin-left: 10px;margin-right: 10px;">
        <button type="button" class="layui-btn layui-btn-normal" id="selectLogo">选择logo</button>
    </div>
    <div class="layui-upload-list" style="display: inline-block">
        <img class="layui-upload-img" id="logo" style="max-height: 320px;max-width: 180px">
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block" style="float: right">
            <button class="layui-btn" lay-submit="" lay-filter="sub">立即提交</button>
        </div>
    </div>
</form>
<jsp:include page="/resources/inc/footer.jsp" />
<script>
    var logo;
    layui.use('upload', function () {
        var form = layui.form
                , layer = layui.layer
                , upload = layui.upload
                , $ = layui.jquery;

        //选完文件后不自动上传
        upload.render({
            elem: '#selectLogo'
            , url: '${ZHENG_OSS_DOMAIN}/qiniu/oss/upload'
            , auto: true
            //,multiple: true
//            , bindAction: '#test9'
            , before: function (obj) {
                //预读本地文件示例，不支持ie8
                obj.preview(function (index, file, result) {
                    $('#logo').attr('src', result); //图片链接（base64）
                });
            }
            , done: function (res) {
                if (res.data == 0) {
                } else {
                    logo = res.data;
                }
            }
        });
    });
    var url = '${basePath}/manage/product/brand/create';
    var index = parent.layer.getFrameIndex(window.name);
    commonSubmit(url, "sub", index);
    function getFormData(data) {
        data.field.logo = logo;
        return JSON.stringify(data.field);
    }
</script>
</body>
</html>
